<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="出库仓库">
             <j-popup placeholder="请选择出库仓库" v-model="queryParam.repositoryName" code="select_repository" org-fields="name,code" dest-fields="repository_name,repository_code" :field="getPopupField('repository_name,repository_code')" :multi="false"/>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="12" :md="12" :sm="24">
            <a-form-item label="出库日期">
          <j-date class="query-group-cust" v-model="queryParam.outTime_begin" placeholder="请选择开始时间" show-time date-format="YYYY-MM-DD HH:mm:ss"/>
          <span class="query-group-split-cust"></span>
          <j-date class="query-group-cust" v-model="queryParam.outTime_end" placeholder="请选择结束时间" show-time date-format="YYYY-MM-DD HH:mm:ss"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="出库人">
               <j-select-user-by-dep placeholder="请选择出库人" v-model="queryParam.outPeople"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="领取人姓名">
             <j-select-user-by-dep placeholder="请选择领取人姓名" v-model="queryParam.personnel"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="领取人所在公司">
             <j-select-depart placeholder="请选择领取人所在公司" v-model="queryParam.company"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="领取人所在部门">
             <j-select-depart placeholder="请选择领取人所在部门" v-model="queryParam.dapartment"/>
            </a-form-item>
          </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('出库记录')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>

      <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="出库物品" key="purchaseStockOutGoods" forceRender>
              <purchase-stock-out-goods-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template>
        <!-- 内嵌table区域 end -->

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="imgSlot" slot-scope="text,record">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" :preview="record.id" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>


        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-space v-else direction="vertical">
            <a-button v-for="item in text.split(',')" :key="item" block ghost type="primary" icon="download" size="small" @click="downloadFile(item)">
              <span>{{item}}</span>
            </a-button>
          </a-space>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <purchase-stock-out-modal ref="modalForm" @ok="modalFormOk"/>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import PurchaseStockOutModal from './modules/PurchaseStockOutModal'
  import PurchaseStockOutGoodsSubTable from './subTables/PurchaseStockOutGoodsSubTable'
  import JDate from '@/components/jeecg/JDate.vue'
  import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
  import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'PurchaseStockOutList',
    mixins: [JeecgListMixin],
    components: {
      PurchaseStockOutModal,
      PurchaseStockOutGoodsSubTable,
      JDate,
      JSelectUserByDep,
      JSelectDepart,
    },
    data() {
      return {
        description: '出库记录列表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t,r,index) => {
              const num = (this.ipagination.current - 1)*this.ipagination.pageSize
              return parseInt(index)+1+num;
            }
          },
          {
            title: '出库单编号',
            align: 'center',
            dataIndex: 'code',
          },
          {
            title: '出库仓库',
            align: 'center',
            dataIndex: 'repositoryName',
          },
          {
            title: '出库日期',
            align: 'center',
            dataIndex: 'outTime',
          },
          {
            title: '出库人',
            align: 'center',
            dataIndex: 'outPeople_dictText'
          },
          {
            title: '领取人姓名',
            align: 'center',
            dataIndex: 'personnel_dictText'
          },
          {
            title: '领取人所在公司',
            align: 'center',
            dataIndex: 'company_dictText'
          },
          {
            title: '领取人所在部门',
            align: 'center',
            dataIndex: 'dapartment_dictText'
          },
          {
            title: '附件',
            align: 'center',
            dataIndex: 'attachment',
            scopedSlots: {customRender: 'fileSlot'}
          },
          {
            title: '出库总金额',
            align: 'center',
            dataIndex: 'total',
          },
          {
            title: '创建人用户',
            align: 'center',
            dataIndex: 'createBy',
          },
          {
            title: '创建时间',
            align: 'center',
            dataIndex: 'createTime',
          },
          {
            title: '最后修改人用户',
            align: 'center',
            dataIndex: 'updateBy',
          },
          {
            title: '最后修改时间',
            align: 'center',
            dataIndex: 'updateTime',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width:147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/purchase/purchaseStockOut/list',
          delete: '/purchase/purchaseStockOut/delete',
          deleteBatch: '/purchase/purchaseStockOut/deleteBatch',
          exportXlsUrl: '/purchase/purchaseStockOut/exportXls',
          importExcelUrl: '/purchase/purchaseStockOut/importExcel',
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      }
    },
    methods: {
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'code',text:'出库单编号',dictCode:''})
        fieldList.push({type:'popup',value:'repositoryName',text:'出库仓库', popup:{code:'select_repository',field:'name',orgFields:'name',destFields:'repository_name'}})
        fieldList.push({type:'datetime',value:'outTime',text:'出库日期'})
        fieldList.push({type:'sel_user',value:'outPeople',text:'出库人'})
        fieldList.push({type:'sel_user',value:'personnel',text:'领取人姓名'})
        fieldList.push({type:'sel_depart',value:'company',text:'领取人所在公司'})
        fieldList.push({type:'sel_depart',value:'dapartment',text:'领取人所在部门'})
        fieldList.push({type:'string',value:'attachment',text:'附件',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'total',text:'出库总金额',dictCode:''})
        fieldList.push({type:'string',value:'createBy',text:'创建人用户',dictCode:''})
        fieldList.push({type:'datetime',value:'createTime',text:'创建时间'})
        fieldList.push({type:'string',value:'updateBy',text:'最后修改人用户',dictCode:''})
        fieldList.push({type:'datetime',value:'updateTime',text:'最后修改时间'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>